
Page({
    data: {
         list:[]

        
    },
    onLoad:function(opt){
       var userInfo= wx.getStorageSync('userInfo');
        this.setData({
            userInfo:userInfo,
            code:opt.code
        })
        this.getSearchList();
    },
    onShow:function(){
        
    },
    updateValue:function(e){
       this.setData({
         searchMode:e.detail.value
       })
    },
    searchAction:function(e){
         this.setData({
           searchMode:e.currentTarget.dataset.item
         })        

        var searchMode= wx.setStorageSync('searchMode',this.data.searchMode);

        wx.navigateBack({
            delta: 1
        })
    },
    addSearch:function(){

      var _self=this;
        wx.request({
            url:getApp().globalData.baseUrl+'/user/search/insert',
            method:"post",
            header:{
               'openid':this.data.userInfo.openid, //公用请求头
               'content-type': 'application/json'
            },
            data:{
              'openid':this.data.userInfo.openid, //公用请求头
              'name':this.data.searchMode
            },
            success: function(res) {
              if (res.data.code==200) {
                var searchMode= wx.setStorageSync('searchMode',_self.data.searchMode);
                wx.navigateBack({
                  delta: 1
                })
              }
            
            
         }
       })
    },
    delectAll:function(){
        var _self=this;
        wx.request({
            url:getApp().globalData.baseUrl+'/user/search/delet',
            method:"get",
            header:{
               'openid':this.data.userInfo.openid, //公用请求头
               'content-type': 'application/json'
            },
            data:{openid:this.data.userInfo.openid},
            success: function(res) {
              if (res.data.code==200) {
                _self.setData({
                  list:[]
                })
              }
            console.log(res)  
            
         }
       })
    },
    getSearchList:function(){
        var _self=this;
        wx.request({
            url:getApp().globalData.baseUrl+'/user/search/list',
            method:"get",
            header:{
               'openid':this.data.userInfo.openid, //公用请求头
               'content-type': 'application/json'
            },
            data:{openid:this.data.userInfo.openid},
            success: function(res) {
              if (res.data.code==200) {
                _self.setData({
                  list:res.data.obj
                })
              }
            console.log(res)  
            
         }
       })
    }
});